﻿[assembly: System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Controls.Additions.CombinedDescriptor.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Controls.Additions.CombinedDescriptor.debug.js", "application/x-javascript")]

namespace BM.Tools.WebControls.MForm.Controls.Additions
{
    using System.Collections.ObjectModel;
    using System.Web.UI;

    using AjaxControlToolkit;

    using Helper;

    /// <summary>
    /// Provides a definition how to dynamically describe an item. 
    /// This definition consists of <see cref="TextDescription"/> and <see cref="ValueDescription"/> definitions.
    /// Text descriptions are static, while value definitions are dynamic and are current client-side values of other items.
    /// </summary>
    [ParseChildren(true, "DescriptionChunks")]
    [ClientScriptResource("BM.Tools.WebControls.MForm",
            "BM.Tools.WebControls.MForm.Controls.Additions.CombinedDescriptor.js")]
    public class CombinedDescriptor : Descriptor
    {        
        private Collection<DescriptionChunk> descriptionChunks = new Collection<DescriptionChunk>();

        /// <summary>
        /// Gets DescriptionChunks.
        /// </summary>
        /// <value>
        /// The description chunks.
        /// </value>
        [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
        [AttributeProperty(Name = "chunks")]
        public Collection<DescriptionChunk> DescriptionChunks
        {
            get
            {
                return descriptionChunks;
            }
        }

        /// <summary>
        /// Adds a new text description with the specified text
        /// </summary>
        /// <param name="text">
        /// The text of the text description
        /// </param>
        public void AddText(string text)
        {
            DescriptionChunks.Add(new TextDescription(text));
        }

        /// <summary>
        /// Adds a value description with the value of the item found under the specified path
        /// </summary>
        /// <param name="path">
        /// The path to the item whose value should be displayed
        /// </param>
        public void AddValue(string path)
        {
            DescriptionChunks.Add(new ValueDescription(path));
        }
    }
}